<?php
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 XOOPS.org                           //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //

include 'header.php';

$lid = isset($_GET['lid']) ? intval($_GET['lid']) : 0;
$cid = isset($_GET['cid']) ? intval($_GET['cid']) : 0;
if ( empty($lid) ) {
	die("No lid!");
} elseif ( empty($cid) ) {
	die("No cid!");
}

$q = "SELECT d.lid, d.cid, d.title, d.url, d.homepage, d.version, d.size, d.platform, d.logourl, d.status, d.date, d.hits, d.rating, d.votes, d.comments, t.description FROM ".$xoopsDB->prefix("mydownloads_downloads")." d, ".$xoopsDB->prefix("mydownloads_text")." t WHERE d.lid=$lid AND d.lid=t.lid AND status>0";
$result=$xoopsDB->query($q);
list($lid, $cid, $title, $url, $homepage, $version, $size, $platform, $logourl, $status, $time, $hits, $rating, $votes, $comments, $description)=$xoopsDB->fetchRow($result);

if ( empty($lid) ) {
	die("No data! Please check its cid and lid!");
}

$can_qrcode = 0;
if ( $mydownloads_can_qrcode == 0 ) {
	$can_qrcode = 0;
}
else if ( $mydownloads_can_qrcode == 1) {
	$can_qrcode = 1;
}
else if ( $mydownloads_can_qrcode == 2) {
	if ( $xoopsUser ) {
	$can_qrcode =1;
	}
	else {
	$can_qrcode =0;
	}
}
else {
	$can_qrcode = 0;
}

if ( empty($can_qrcode) ) {
	die("Not allowed now!");
}

$myts =& MyTextSanitizer::getInstance();

function mydownloads_qrcode_convert_encoding($str, $to = 'SJIS', $from = _CHARSET) 
{
	if (function_exists('mb_convert_encoding')) {
		if (is_array($str)) {
			foreach ($str as $key=>$val) {
				$str[$key] = mydownloads_qrcode_convert_encoding($val, $to, $from);
			}
			return $str;
		} else {
			return mb_convert_encoding($str, $to, $from);
		}
	}else {
		return $str;
	}
}

function mydownloads_qrcode_encoding($data="") {
$data = mydownloads_qrcode_convert_encoding($data);
$data = rawurlencode($data);
$data = ereg_replace("%20", "+", $data);
return $data;
}

$down_data = array();
$down_data['text'] = $myts->makeTareaData4Show($description,0);
$down_data['title'] = $myts->makeTboxData4Show($title);
$down_data['url'] = $myts->makeTboxData4Show($url);
$data = $down_data['title']."\r\n".$down_data['url']."\r\n".$down_data['text'];
$qrcodedata = mydownloads_qrcode_encoding($data);
$linkqrcode = "<img alt='qrcode of linkdata' title='qrcode of linkdata'src='".XOOPS_URL."/modules/qrcode/qrcode_image.php?d=$qrcodedata&amp;e=M&amp;s=4&amp;v=0&amp;t=P&amp;rgb=000000' />\n";

echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n";
echo "<html>\n<head>\n";
echo "<title>" . $xoopsConfig['sitename'] . "</title>\n";
echo "<meta http-equiv='Content-Type' content='text/html; charset=" . _CHARSET . "' />\n";
echo "<meta name='AUTHOR' content='" . $xoopsConfig['sitename'] . "' />\n";
echo "<meta name='COPYRIGHT' content='Copyright (c) ".date('Y')." by " . $xoopsConfig['sitename'] . "' />\n";
echo "<meta name='DESCRIPTION' content='" . $xoopsConfig['slogan'] . "' />\n";
echo "<meta name='GENERATOR' content='" . XOOPS_VERSION . "' />\n\n\n";
echo "<body bgcolor='#ffffff' text='#000000'>
<div style='width: 750px; border: 1px solid #000; padding: 20px;'>
<div style='text-align: center; display: block; margin: 0 0 6px 0;'>
<h2 style='margin: 0;'>"._MD_MYDOWNLOADS_FILETITLE."&nbsp;".$down_data['title']."</h2></div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>"._MD_MYDOWNLOADS_DLURL."&nbsp;:&nbsp;".$down_data['url']."</div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>"._MD_MYDOWNLOADS_DESCRIPTIONC."<br />".$down_data['text']."</div>
<div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'></div>
<div style='text-align: left'>LINK DATA QRCODE<br />".$linkqrcode."</div>
<div style='padding-top: 12px; border-top: 2px solid #ccc;'></div>
<p>From: &nbsp;".XOOPSMYDOWNLOADURL."/singlefile.php?cid=".$cid."&amp;lid=".$lid."</p>
</div>
<br />";
echo "<br /></body></html>";


?>